/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * File Name          : freertos.c
 * Description        : Code for freertos applications
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2025 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "lcd.h"
#include "semphr.h"
#include "queue.h"
#include "key_led.h"
#include "file_opera.h"
#include "ff.h"
#include <stdio.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for Task_SD_Write */
osThreadId_t Task_SD_WriteHandle;
const osThreadAttr_t Task_SD_Write_attributes = {
  .name = "Task_SD_Write",
  .stack_size = 5120 * 4,
  .priority = (osPriority_t) osPriorityNormal1,
};
/* Definitions for Task_ESP8266 */
osThreadId_t Task_ESP8266Handle;
const osThreadAttr_t Task_ESP8266_attributes = {
  .name = "Task_ESP8266",
  .stack_size = 512 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Task_W25Q256 */
osThreadId_t Task_W25Q256Handle;
const osThreadAttr_t Task_W25Q256_attributes = {
  .name = "Task_W25Q256",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Task_Key_Scan */
osThreadId_t Task_Key_ScanHandle;
const osThreadAttr_t Task_Key_Scan_attributes = {
  .name = "Task_Key_Scan",
  .stack_size = 256 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Task_LCD_Displa */
osThreadId_t Task_LCD_DisplaHandle;
const osThreadAttr_t Task_LCD_Displa_attributes = {
  .name = "Task_LCD_Displa",
  .stack_size = 1024 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Task_Wav_Create */
osThreadId_t Task_Wav_CreateHandle;
const osThreadAttr_t Task_Wav_Create_attributes = {
  .name = "Task_Wav_Create",
  .stack_size = 2048 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Task_LCD_ShowWa */
osThreadId_t Task_LCD_ShowWaHandle;
const osThreadAttr_t Task_LCD_ShowWa_attributes = {
  .name = "Task_LCD_ShowWa",
  .stack_size = 512 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};
/* Definitions for Queue_KeyNumbers */
osMessageQueueId_t Queue_KeyNumbersHandle;
const osMessageQueueAttr_t Queue_KeyNumbers_attributes = {
  .name = "Queue_KeyNumbers"
};
/* Definitions for Queue_FileType */
osMessageQueueId_t Queue_FileTypeHandle;
const osMessageQueueAttr_t Queue_FileType_attributes = {
  .name = "Queue_FileType"
};
/* Definitions for Queue_FileTypeWriting */
osMessageQueueId_t Queue_FileTypeWritingHandle;
const osMessageQueueAttr_t Queue_FileTypeWriting_attributes = {
  .name = "Queue_FileTypeWriting"
};
/* Definitions for Queue_FileEvent */
osMessageQueueId_t Queue_FileEventHandle;
const osMessageQueueAttr_t Queue_FileEvent_attributes = {
  .name = "Queue_FileEvent"
};
/* Definitions for Queue_FileSizeTotal */
osMessageQueueId_t Queue_FileSizeTotalHandle;
const osMessageQueueAttr_t Queue_FileSizeTotal_attributes = {
  .name = "Queue_FileSizeTotal"
};
/* Definitions for BinSem_usart3_get */
osSemaphoreId_t BinSem_usart3_getHandle;
const osSemaphoreAttr_t BinSem_usart3_get_attributes = {
  .name = "BinSem_usart3_get"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void AppTask_SD_Write(void *argument);
void AppTask_ESP8266(void *argument);
void AppTask_W25Q256(void *argument);
void AppTask_Key_Scan(void *argument);
void AppTask_LCD_Display(void *argument);
void AppTask_Wav_Create(void *argument);
void AppTask_LCD_ShowWavSize(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
	/* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* Create the semaphores(s) */
  /* creation of BinSem_usart3_get */
  BinSem_usart3_getHandle = osSemaphoreNew(1, 1, &BinSem_usart3_get_attributes);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
	/* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
	/* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of Queue_KeyNumbers */
  Queue_KeyNumbersHandle = osMessageQueueNew (1, sizeof(uint8_t), &Queue_KeyNumbers_attributes);

  /* creation of Queue_FileType */
  Queue_FileTypeHandle = osMessageQueueNew (1, sizeof(uint8_t), &Queue_FileType_attributes);

  /* creation of Queue_FileTypeWriting */
  Queue_FileTypeWritingHandle = osMessageQueueNew (1, sizeof(uint8_t), &Queue_FileTypeWriting_attributes);

  /* creation of Queue_FileEvent */
  Queue_FileEventHandle = osMessageQueueNew (1, sizeof(uint8_t), &Queue_FileEvent_attributes);

  /* creation of Queue_FileSizeTotal */
  Queue_FileSizeTotalHandle = osMessageQueueNew (1, sizeof(uint32_t), &Queue_FileSizeTotal_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
	/* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of Task_SD_Write */
  Task_SD_WriteHandle = osThreadNew(AppTask_SD_Write, NULL, &Task_SD_Write_attributes);

  /* creation of Task_ESP8266 */
  Task_ESP8266Handle = osThreadNew(AppTask_ESP8266, NULL, &Task_ESP8266_attributes);

  /* creation of Task_W25Q256 */
  Task_W25Q256Handle = osThreadNew(AppTask_W25Q256, NULL, &Task_W25Q256_attributes);

  /* creation of Task_Key_Scan */
  Task_Key_ScanHandle = osThreadNew(AppTask_Key_Scan, NULL, &Task_Key_Scan_attributes);

  /* creation of Task_LCD_Displa */
  Task_LCD_DisplaHandle = osThreadNew(AppTask_LCD_Display, NULL, &Task_LCD_Displa_attributes);

  /* creation of Task_Wav_Create */
  Task_Wav_CreateHandle = osThreadNew(AppTask_Wav_Create, NULL, &Task_Wav_Create_attributes);

  /* creation of Task_LCD_ShowWa */
  Task_LCD_ShowWaHandle = osThreadNew(AppTask_LCD_ShowWavSize, NULL, &Task_LCD_ShowWa_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
	/* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
	/* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_AppTask_SD_Write */
/**
 * @brief  Function implementing the Task_SD_Write thread.
 * @param  argument: Not used
 * @retval None
 */
/* USER CODE END Header_AppTask_SD_Write */
__weak void AppTask_SD_Write(void *argument)
{
  /* USER CODE BEGIN AppTask_SD_Write */
	/* Infinite loop */
	for (;;)
	{
		osDelay(1);
	}
  /* USER CODE END AppTask_SD_Write */
}

/* USER CODE BEGIN Header_AppTask_ESP8266 */
/**
 * @brief Function implementing the Task_ESP8266 thread.
 * @param argument: Not used
 * @retval None
 */
/* USER CODE END Header_AppTask_ESP8266 */
__weak void AppTask_ESP8266(void *argument)
{
  /* USER CODE BEGIN AppTask_ESP8266 */
	/* Infinite loop */
	for (;;)
	{
		osDelay(1);
	}
  /* USER CODE END AppTask_ESP8266 */
}

/* USER CODE BEGIN Header_AppTask_W25Q256 */
/**
 * @brief Function implementing the Task_W25Q256 thread.
 * @param argument: Not used
 * @retval None
 */
/* USER CODE END Header_AppTask_W25Q256 */
__weak void AppTask_W25Q256(void *argument)
{
  /* USER CODE BEGIN AppTask_W25Q256 */
	/* Infinite loop */
	for (;;)
	{
		osDelay(1);
	}
  /* USER CODE END AppTask_W25Q256 */
}

/* USER CODE BEGIN Header_AppTask_Key_Scan */
/**
 * @brief Function implementing the Task_Key_Scan thread.
 * @param argument: Not used
 * @retval None
 */
/* USER CODE END Header_AppTask_Key_Scan */
__weak void AppTask_Key_Scan(void *argument)
{
  /* USER CODE BEGIN AppTask_Key_Scan */
	/* Infinite loop */
	for (;;)
	{
		osDelay(1);
	}
  /* USER CODE END AppTask_Key_Scan */
}

/* USER CODE BEGIN Header_AppTask_LCD_Display */
/**
 * @brief Function implementing the Task_LCD_Displa thread.
 * @param argument: Not used
 * @retval None
 */
/* USER CODE END Header_AppTask_LCD_Display */
__weak void AppTask_LCD_Display(void *argument)
{
  /* USER CODE BEGIN AppTask_LCD_Display */
  /* Infinite loop */
  for(;;)
  {
	osDelay(1);
  }
  /* USER CODE END AppTask_LCD_Display */
}

/* USER CODE BEGIN Header_AppTask_Wav_Create */
/**
* @brief Function implementing the Task_Wav_Create thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_AppTask_Wav_Create */
__weak void AppTask_Wav_Create(void *argument)
{
  /* USER CODE BEGIN AppTask_Wav_Create */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END AppTask_Wav_Create */
}

/* USER CODE BEGIN Header_AppTask_LCD_ShowWavSize */
/**
* @brief Function implementing the Task_LCD_ShowWa thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_AppTask_LCD_ShowWavSize */
__weak void AppTask_LCD_ShowWavSize(void *argument)
{
  /* USER CODE BEGIN AppTask_LCD_ShowWavSize */
  /* Infinite loop */
  for(;;)
  {
	osDelay(1);
  }
  /* USER CODE END AppTask_LCD_ShowWavSize */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

